package com.itheima.project.web;


import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.project.basic.ResponseWrap;
import com.itheima.project.core.enums.content.ContentRuleDetailEnum;
import com.itheima.project.face.ContentRuleDetailFace;
import com.itheima.project.utils.ResponseWrapBuild;
import com.itheima.project.vo.content.ContentRuleDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;

/**
 * @Description：前端控制器
 */
@Slf4j
@Api(tags = "controller")
@RestController
@RequestMapping("content-rule-detail")
public class ContentRuleDetailController {

    @Autowired
    ContentRuleDetailFace contentRuleDetailFace;

    /***
     * @description 多条件查询分页列表
     * @param contentRuleDetailVo Vo查询条件
     * @param pageNum 页码
     * @param pageSize 每页条数
     * @return: Page<ContentRuleDetailVo>
     */
    @PostMapping("page/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页",notes = "分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "contentRuleDetailVo",value = "Vo对象",required = true,dataType = "ContentRuleDetailVo"),
        @ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
        @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
    })
    public ResponseWrap<Page<ContentRuleDetailVo>> findContentRuleDetailVoPage(
                                    @RequestBody ContentRuleDetailVo contentRuleDetailVo,
                                    @PathVariable("pageNum") int pageNum,
                                    @PathVariable("pageSize") int pageSize) {
        Page<ContentRuleDetailVo> contentRuleDetailVoPage = contentRuleDetailFace.findContentRuleDetailVoPage(contentRuleDetailVo, pageNum, pageSize);
        return ResponseWrapBuild.build(ContentRuleDetailEnum.SUCCEED,contentRuleDetailVoPage);
    }

    /**
     * @Description 保存
     * @param contentRuleDetailVo Vo对象
     * @return ContentRuleDetailVo
     */
    @PutMapping
    @ApiOperation(value = "添加ContentRuleDetail",notes = "添加ContentRuleDetail")
    @ApiImplicitParam(name = "contentRuleDetailVo",value = "Vo对象",required = true,dataType = "ContentRuleDetailVo")
    public ResponseWrap<ContentRuleDetailVo> createContentRuleDetail(@RequestBody ContentRuleDetailVo contentRuleDetailVo) {
        ContentRuleDetailVo contentRuleDetailVoResult = contentRuleDetailFace.createContentRuleDetailVo(contentRuleDetailVo);
        return ResponseWrapBuild.build(ContentRuleDetailEnum.SUCCEED,contentRuleDetailVoResult);
    }

    /**
     * @Description 修改
     * @param contentRuleDetailVo Vo对象
     * @return Boolean 是否修改成功
     */
    @PatchMapping
    @ApiOperation(value = "修改",notes = "修改")
    @ApiImplicitParam(name = "contentRuleDetailVo",value = "Vo对象",required = true,dataType = "ContentRuleDetailVo")
    public ResponseWrap<Boolean> updateContentRuleDetail(@RequestBody ContentRuleDetailVo contentRuleDetailVo) {
        Boolean flag = contentRuleDetailFace.updateContentRuleDetailVo(contentRuleDetailVo);
        return ResponseWrapBuild.build(ContentRuleDetailEnum.SUCCEED,flag);
    }

    /**
     * @Description 删除
     * @param contentRuleDetailVo 刪除条件：checkedIds 不可为空
     * @return
     */
    @DeleteMapping
    @ApiOperation(value = "删除",notes = "删除")
    @ApiImplicitParam(name = "contentRuleDetailVo",value = "Vo对象",required = true,dataType = "ContentRuleDetailVo")
    public ResponseWrap<Boolean> deleteContentRuleDetail(@RequestBody ContentRuleDetailVo contentRuleDetailVo) {
        Boolean flag = contentRuleDetailFace.deleteContentRuleDetailVo(contentRuleDetailVo.getCheckedIds());
        return ResponseWrapBuild.build(ContentRuleDetailEnum.SUCCEED,flag);
    }

    /***
     * @description 多条件查询列表
     * @param contentRuleDetailVo Vo对象
     * @return List<ContentRuleDetailVo>
     */
    @PostMapping("list")
    @ApiOperation(value = "多条件查询列表",notes = "多条件查询列表")
    @ApiImplicitParam(name = "contentRuleDetailVo",value = "Vo对象",required = true,dataType = "ContentRuleDetailVo")
    public ResponseWrap<List<ContentRuleDetailVo>> contentRuleDetailList(@RequestBody ContentRuleDetailVo contentRuleDetailVo) {
        List<ContentRuleDetailVo> contentRuleDetailVoList = contentRuleDetailFace.findContentRuleDetailVoList(contentRuleDetailVo);
        return ResponseWrapBuild.build(ContentRuleDetailEnum.SUCCEED,contentRuleDetailVoList);
    }

}
